﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Input;
using XNAGuiLib.Core.Events;

namespace XNAGuiLib.Core.ActionHandling
{
    public class KeyAction : Action
    {

        #region KeyAction Public Field - KeyMods
        List<KeyModifier> _keyMods;
        /// <summary>
        /// gets or sets the list of KeyModifiers for this KeyAction
        /// </summary>
        public List<KeyModifier> KeyMods
        {
            get { return _keyMods; }
            set { _keyMods = value; }
        }
        #endregion


        public KeyAction(GIComponent invoker, IAction target, string command, KeyModifier[] keyModifier)
            : base(invoker, target, command)
        {
            _keyMods = new List<KeyModifier>(keyModifier);
            invoker.Add(this);
        }

        #region Action Override Method - Check
        protected override void Check(MouseState ms, KeyboardState ks)
        {
            if (_enabled)
            {
                _ks = Keyboard.GetState();
                _ms = Mouse.GetState();

                bool modified = false;

                foreach (KeyModifier keymod in _keyMods)
                {
                    if (!keymod.CheckKeyModifier(_ks, _oks))
                    {
                        modified = false;
                        break;
                    }
                    else modified = true;
                }

                if (modified)
                {
                    _target.Execute(this.Command);
                }


                _oks = _ks;
                _oms = _ms;
            }
        }
        #endregion
    }
}
